package com.itheima.dao.store;

import com.itheima.domain.store.Course;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

/**
 * 学科管理(数据层)
 */
public interface CourseDao {

    /**
     * 查询所有
     */
    @Select("SELECT * FROM st_course")
    @Results(id = "courseMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.VARCHAR, javaType = String.class),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR, javaType = String.class),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR, javaType = String.class),
            @Result(column = "state", property = "state", jdbcType = JdbcType.VARCHAR, javaType = String.class),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP, javaType = Date.class),
    })
    List<Course> findAll();

    /**
     * 根据ID查询对应的学科
     */
    @Select("select * from st_course where id = #{id}")
    @ResultMap("courseMap")
    Course findById(String id);

    /**
     * 保存
     */
    @Insert("insert into st_course(id,name,remark,state,create_time) values(#{id},#{name},#{remark},#{state},#{createTime})")
    int save(Course course);

    /**
     * 更新
     */
    @Update("update st_course set name=#{name}, remark=#{remark}, state=#{state} where id=#{id}")
    int update(Course course);

    /**
     * 根据ID删除
     */
    @Delete("delete from st_course where id = #{id}")
    int deleteById(String id);
}
